package com.my.oauth2.server.clien;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
/**
 * Created by yanhao on 2017/5/26.
 */
@Service
@Slf4j
public class OssClientDetailsService implements ClientDetailsService{
    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        log.warn("loadClientByClientId");
        OssApp app = new OssApp();
        app.setAppId("123456");
        app.setSecret("654321");
        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        authorities.add(new SimpleGrantedAuthority("READ"));
        authorities.add(new SimpleGrantedAuthority("WRITE"));
        app.setAuthorities(authorities);
        // 授权类型
        Set<String> authorizedGrantTypes = new TreeSet<String>();
        authorizedGrantTypes.add("password");
        authorizedGrantTypes.add("refresh_token");
        authorizedGrantTypes.add("authorization_code");
        app.setAuthorizedGrantTypes(authorizedGrantTypes);
        Set<String> scope = new TreeSet<String>();
        scope.add("openid");
        app.setScope(scope);
        return app;
    }
}